import { reactive } from 'vue'

export const useDeleteItem = () => {
  const state = reactive({
    arr: [
      {
        id: 0,
        name: 'ifer',
      },
      {
        id: 1,
        name: 'elser',
      },
      {
        id: 2,
        name: 'xxx',
      },
    ],
  })
  const handleDelete = (id) => {
    const idx = state.arr.findIndex(item => item.id === id)
    state.arr.splice(idx, 1)
  }
  return { state, handleDelete }
}
export const useAddItem = (state) => {
  const user = reactive({
    id: '',
    name: ''
  })
  const addItem = () => {
    state.arr.push({
      ...user
    })
    user.id = ''
    user.name = ''
  }
  return { user, addItem }
}